// pages/ucenter/add_comment/add_comment.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        orderList:[
            {
                id:'',
                picUrl:'/images/1.png',
                name:'追源深山土蜂蜜',
                value:5,
                comment:''
            },
            {
                id:'',
                picUrl:'/images/1.png',
                name:'追源深山土蜂蜜',
                value:5,
                comment:''
            },
        ]

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let shareid = options.shareid;

        if (shareid){
            wx.setStorageSync('shareid', shareid);
        }

        let orderlist = options.orderlist;
        orderlist = JSON.parse(orderlist);

        orderlist.forEach(element => {
            element.value = 5;
        });
        this.setData({
            orderList:orderlist
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        return {
            title:'sharetest',
            path:'/pages/index/index?shareid=' + '54185418'
        }
    },
    /**
     * (评价分数反馈)
     * @param {*} e 
     * @徐志鹏
     * @2021-2-19
     */
    onChange:function(e){
        let index = e.currentTarget.dataset.index;
        let orderlist = this.data.orderList;

        orderlist[index].value = e.detail;
        this.setData({
            orderList:orderlist
        })
    },
    /**
     * (评价提交)
     * @param {*} e 
     * @徐志鹏
     * @2021-2-19
     */
    comment:function(){
        let orderlist = this.data.orderList;

        orderlist.forEach(e=>{
            if (!e.comment){
                wx.showToast({
                  title: '请填写完整评论信息',
                  icon: 'none'
                })
            }
            return;
        })
    },
    bindinput:function(e){
        let comment = e.detail.value;
        let index = e.currentTarget.dataset.index;
        let orderlist = this.data.orderList;

        orderlist[index].comment = comment;
        this.setData({
            orderList:orderlist
        })
    }
})